package aistar.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
    public class CartDAOImpl implements CartDAO {
        @Autowired
        private JdbcTemplate jdbcTemplate;

        @Override
        public void addToCart(Cart cart) {
            String sql = "INSERT INTO cart (productId, quantity, price) VALUES (?, ?, ?)";
            jdbcTemplate.update(sql, cart.getProductId(), cart.getQuantity(), cart.getPrice());
        }

        @Override
        public List<Cart> getCartItems() {
            String sql = "SELECT * FROM cart";
            return jdbcTemplate.query(sql, new CartRowMapper());
        }


    }


